import os
import sys
from modules.converterbase import *

ignorefiles = set(['__init__.py', 'converterbase.py'])
ignoreclasses = set(['ConverterBase', 'callstatic','getstatic'])

# The purpose of this program is to load in and then run the appropriate
# converter object or series of converter objects on a file.
# To add new converter objects, simply create a new class or classes, and
# place them in the modules subdirectory.


#we're going to have to go through every .py file in the modules subdirectory,
#adding every converter class to a registry so we can look them up and call them
#later based on what their registered conversion is.


# Converters are stored in a dictionary of dictionaries.  The Primary key
# represents the base type, the Secondary keys represent the possible destination
# types, and finally the values are the conversion functions themselves.
converters = dict()

# import all of our library modules from /modules

convertermods = set()
for name in os.listdir("modules"):
    if name.endswith(".py") and name not in ignorefiles:
        print name
        name = os.path.splitext(name)[0]
        pathname = "modules.{0}".format(name)
        print name, pathname
        __import__(pathname)
        convertermods.add(sys.modules[pathname])
        

print "names:"
for v in convertermods:
    for name,classtype in v.__dict__.items():
        
        if(not name.startswith("__") and name not in ignoreclasses):
            converters[callstatic(classtype,'getBaseType')] = { callstatic(classtype, 'getBaseType'):getstatic(classtype,'convert') }
            
   
inFile = open("test.txt", 'r')
outFile = open("out.txt", 'w') 

for i in converters:
    print i
    #i.convert(inFile,outFile)
